﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="host.aspx.cs" Inherits="Activity_Live_host" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <Custom:Header ID="Header1" runat="server" />
    <style type="text/css">
        .pupbox{width:330px;padding:10px;}
        .pupbox ul li{line-height:30px;}
        .loading2{padding-left:18px;line-height:22px; background-position:left center;display:none;}
    </style>
    <script type="text/javascript">
        $(function () {
            var wbox = $("a:contains(添加)").click(function () {
                return false;
            }).wBox({
                title: "添加主持人",
                html: "<div class='pupbox'><ul><li>主持人名称：<input name='hostname' /></li><li>&nbsp;&nbsp;头像地址：<input name='pic' style='width:230px' /></li><li>注：请上传50×50像素的头像 <li><input type='button' class='btnsave' value='保存' /><span class='loading2'>数据提交中…</span></li></ul></div>",
                show: false,
                callBack: function () {
                    $(".btnsave").click(function () {
                        var obj = $(this);
                        var parent = obj.next();
                        if (parent.is(":visible")) return false;
                        var postdata = { action: "host_save", name: $("input[name=hostname]").val(), pic: $("input[name=pic]").val() };
                        $.ajax({
                            url: "/ajaxdata/activity/",
                            type: "POST",
                            dataType: "json",
                            data: postdata,
                            success: function (data) {
                                if (data.succ) {
                                    alert("提交成功。");
                                    location = "?";
                                }
                                else {
                                    alert(data.msg);
                                }
                            },
                            error: function (data, status, e) {
                                alert("提交发生意外。")
                                $("body").append(data.responseText)
                            },
                            beforeSend: function () {
                                obj.hide();
                                parent.show();
                            },
                            complete: function () {
                                parent.hide();
                                obj.show();
                            }
                        });
                    });
                }
            });

            var host_id = 0;
            var wbox = $(".edit").click(function () {
                host_id = $(this).attr("rcid");
            }).wBox({
                title: "修改主持人",
                html: "<div class='pupbox'><ul><li>主持人名称：<input name='hostname' /></li><li>&nbsp;&nbsp;头像地址：<input name='pic' style='width:230px' /></li><li><input type='button' class='btnsave' value='保存' /><span class='loading2'>数据提交中…</span></li></ul></div>",
                show: false,
                callBack: function () {
                    $("input[name=hostname]").val($.trim($(".name_" + host_id).text()));
                    $("input[name=pic]").val($(".pic_" + host_id).attr("src"));
                    $(".btnsave").click(function () {
                        var obj = $(this);
                        var parent = obj.next();
                        if (parent.is(":visible")) return false;
                        var postdata = { action: "host_save", host_id: host_id, name: $("input[name=hostname]").val(), pic: $("input[name=pic]").val() };
                        $.ajax({
                            url: "/ajaxdata/activity/",
                            type: "POST",
                            dataType: "json",
                            data: postdata,
                            success: function (data) {
                                if (data.succ) {
                                    $(".name_" + host_id).text($("input[name=hostname]").val());
                                    $(".pic_" + host_id).attr("src", $("input[name=pic]").val());
                                    wbox.close();
                                }
                                else {
                                    alert(data.msg);
                                }
                            },
                            error: function (data, status, e) {
                                alert("提交发生意外。")
                                $("body").append(data.responseText)
                            },
                            beforeSend: function () {
                                obj.hide();
                                parent.show();
                            },
                            complete: function () {
                                parent.hide();
                                obj.show();
                            }
                        });
                    });
                }
            });

            $("a:contains(删除)").click(function () {
                var ids = "";
                $("input[name=checkboxid]:checked").each(function () {
                    ids += $(this).val() + ","
                });
                if (ids == "") {
                    alert("未选中任何待删除记录");
                } else {
                    $.ajax({
                        url: "/ajaxdata/activity/",
                        dataType: "json",
                        data: { action: "img_del", ids: ids },
                        success: function (data) {
                            if (data.succ) {
                                $("input[name=checkboxid]:checked").each(function () {
                                    $("tr[imgid=" + $(this).val() + "]").remove();
                                });

                            } else {
                                $.each(data.ids, function (val, i) {
                                    $("tr[imgid=" + val + "]").remove();
                                });
                                alert(data.msg);
                            }
                        },
                        error: function (req) {
                            alert("提交发生意外。");
                        },
                        beforeSend: function () {

                        },
                        complete: function () {

                        }
                    });
                }
                return false;
            });

        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
     <Custom:ToolBar ID="ToolBar" runat="server" />
        <table  border="0" class="tabList" align="center" cellpadding="0" cellspacing="1">
        <tr class="tbhead">
            <td width="60" align=center>
                全<input type="checkbox" id="chkall" />选
            </td>
            <td>
               呢称
            </td>
            <td>头像</td>
            <td>操作</td>
        </tr>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <tr rcid="<%#Eval("id") %>">
                <td>
                    <div align="center">
                        <input name="checkboxid" type="checkbox" value="<%#Eval("ID") %>" />
                    </div>
                </td>
                <td class="name_<%#Eval("id") %>">
                   <%#Eval("name")%>
                </td>
                <td ><img class="pic_<%#Eval("id") %>" src="<%#Eval("pic") %>" style="max-height:80px" /></td>
                <td>
                    <a class="edit"  href="#" rcid="<%#Eval("id") %>">修改</a>
                </td>
            </tr>
            </ItemTemplate>
        </asp:Repeater>
    </table>

    </form>
</body>
</html>
